﻿@page "/weather"
@using Aos.Components.Pages.Forms

@inherits BaseComponent

<PageTitle>Weather</PageTitle>

<TablePage Model="model" />


@code {
    private TableModel<WeatherForecast> model;

    protected override async Task OnInitAsync()
    {
        await base.OnInitAsync();
        model = new TableModel<WeatherForecast>(this, TableColumnMode.Property);
        model.ShowPager = true;
        model.Name = "天气";
        model.OnQuery =async c =>
        {
            // Simulate asynchronous loading to demonstrate a loading indicator
            await Task.Delay(500);

            var startDate = DateOnly.FromDateTime(DateTime.Now);
            var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" };
            var  forecasts = Enumerable.Range(1, c.PageSize).Select(index => new WeatherForecast
                {
                    Date = startDate.AddDays(index),
                    TemperatureC = Random.Shared.Next(-20, 55),
                    Summary = summaries[Random.Shared.Next(summaries.Length)]
                }).ToList();
            return new PagingResult<WeatherForecast>(100, forecasts);
        };
        model.FormType = typeof(WeatherForm);
        model.Toolbar.AddAction(nameof(New));
    }

    public void New()
    {
        model.NewForm(OnSaveAsync, new WeatherForecast());
    }
    private Task<Known.Result  > OnSaveAsync(WeatherForecast data)
    {
        return Known.Result.SuccessAsync(data.Summary);
    }

}